<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<title>电子病历列表</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="电子病历,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" />
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./css/wx.css" />
<link rel="stylesheet" href="./css/weui.css" />
<link rel="stylesheet" href="./css/example.css" />
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<style type="text/css">

</style>
</head>
<script type="text/javascript">

// 屏蔽屏幕自身手势
// document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
var storage = window.localStorage;
var userCode = storage.getItem("primaryRole");
var roleCode = storage.getItem("currentRole");
var name = storage.getItem("currentName");	

$(document).ready(function() {
	$("#userName").html("("+name+")");
	$("#basehistory").show();
});

//切换角色
function changeRole(){
	$.ajax({
 	url: "./user/getRoles",
       	type: "POST",
       	data : {
       		primaryRole : storage.getItem("primaryRole")
       	},
      	dataType: 'json',
       	cache: false,
       	success: function (ret) {
       		if(ret.resultCode==0){
       			roleMenu();
       			var roleHTML="";
	        	$("#role").html("");
               	for(var i=0;i<ret.content.length;i++){
               		roleHTML+="<label class=\"weui_cell weui_check_label\" for=\"x"+(i+1)+"\">";
                roleHTML+="<div class=\"weui_cell_bd weui_cell_primary\">";
	                roleHTML+=" <p>"+ret.content[i].userName+"</p> </div>";
				 	roleHTML+="<div class=\"weui_cell_ft\">";
				 	roleHTML+="<input type=\"radio\" class=\"weui_check\" name=\"radio100\" id=\"x"+(i+1)+"\" value="+ret.content[i].userCode+">";
				 	roleHTML+="<span class=\"weui_icon_checked\"></span>";
				 	roleHTML+="</div></label>";
			 	}
				$("#role").html(roleHTML);
       		}else{
       			alert(ret.msg);
       			window.location.href = "./jsp/login.jsp";
       		}
      	}
   	});
}

function roleMenu(){
    var w_height = $(window).height();
    $('.theleftmenu').css('height',w_height);
    $('.theleftmenu').css('display','block');
    //   弹出边菜单
    $('.theleftmenu .bg_mark').css('display','block');
    
    $('.theleftmenu .theleftmenu_con ' ).stop().animate({ left: '0' }, 400);
    $('.cancle').click(function(){
    	  $('.theleftmenu').css('height',w_height);
        $('.theleftmenu .leftmenu_con ').stop().animate({ left: '-100%' }, 400);
        setTimeout(function(){
            $('.theleftmenu,.bg_mark').fadeOut('fast');
        },200);
    });
}

function commit(){
	var w_height = $(window).height();
	var val = $("input[name='radio100']:checked").val();
	if(val==storage.getItem("primaryRole")){//如果选择的和主用户一样
		storage.setItem("currentRole",val);
		storage.setItem("isMainRole",1);
	}else{
		storage.setItem("currentRole",val);
		storage.setItem("isMainRole",0);
	}
	$.ajax({
       	url: "./user/currRole",
       	type: "POST",
       	data:{
       		currRole : val,
			isMainRole : storage.getItem("isMainRole")          		
       	},
       	dataType: 'json',
       	cache: false,
       	success: function (ret) {
         	if (ret.resultCode==0) {
       	   	  	$('.theleftmenu').css('height',w_height);
       	      	$('.theleftmenu .theleftmenu_con ').stop().animate({ left: '-100%' }, 400);
       	      	setTimeout(function(){
       	          	$('.theleftmenu,.bg_mark').fadeOut('fast');
       	      	},200);
       	      	var now = getSmpFormatNowDate(false);
       	      	var birth = getSmpFormatDateByLong(ret.content.birth,false);
       	      	/* var age = DateDiff(now,birth);//多少天  */
       	      	var age = ret.content.day;
       	      	var sex = ret.content.sex;
       	      	storage.setItem("curSex",sex);
       	      	storage.setItem("curage",age);
      	      	storage.setItem("currentName",ret.content.userName);
  				ageFlag = dayToAgeFlag(age);
        	  	storage.setItem("curAgeFlag",ageFlag);
        	  	window.location.reload();
          }
       }
   });
}

function addPic() {
	window.location.href = "./jsp/caseHistory/uploadPic.jsp";
}

function delBaseHis(id){
	$(".baseclass").removeAttr("onclick");
	var url= "./diseaseHistory/delImgORBaseHis.spring";
	 $.ajax({
		　　url : url,
		　　data : {id:id},
		　　type : "POST",
		  dataType: 'json',
		　　success : function(data) {
			console.log(data.resultCode);
			if(data.resultCode=='1'){
				alert("删除成功");
				toLoad();
			}else{
			alert("删除失败，请稍后重试");
			toLoad();
			}
		　　}
		});
}
function delImgHis(id){
	$(".picclass").removeAttr("onclick");
	var url= "./diseaseHistory/delImgORBaseHis.spring";
	 $.ajax({
		　　url : url,
		　　data : {id:id},
		　　type : "POST",
		  dataType: 'json',
		　　success : function(data) {
			console.log(data.resultCode);
			if(data.resultCode=='1'){
				alert("删除成功");
				toLoad();
			}else{
			alert("删除失败，请稍后重试");
			toLoad();
			}
		　　}
		});
}

function delSysHis(id){
	$(".sysclass").removeAttr("onclick");
	var url= "./diseaseHistory/delSysHis.spring";
	 $.ajax({
		　　url : url,
		　　data : {id:id},
		　　type : "POST",
		  dataType: 'json',
		　　success : function(data) {
			console.log(data.resultCode);
			if(data.resultCode=='1'){
				alert("删除成功");
				toLoad();
			}else{
			alert("删除失败，请稍后重试");
			toLoad();
			}
		　　}
		});
}

/**
 * 打开电子病历列表
 */
function toCaseHistory(id){
	var $loadingToast = $('#loadingToast');
	if ($loadingToast.css('display') != 'none') {
		return;
	}
	$loadingToast.show();
	var url="./jsp/caseHistory/caseHistoryEdit.jsp?id="+id;
	window.location.href=url;
	$loadingToast.hide();
}


function toSysCaseHistory(id){
	var $loadingToast = $('#loadingToast');
	if ($loadingToast.css('display') != 'none') {
		return;
	}
	$loadingToast.show();
	var url="./jsp/caseHistory/sysCaseHistoryView.jsp?id="+id;
	window.location.href=url;
	$loadingToast.hide();
}

function toImgCaseHistory(id){
	var $loadingToast = $('#loadingToast');
	if ($loadingToast.css('display') != 'none') {
		return;
	}
	$loadingToast.show();
	var url="./jsp/caseHistory/imgCaseHistoryView.jsp?id="+id;
	window.location.href=url;
	$loadingToast.hide();
}

/**
 * 病历保存
 */
function toSaveCase(id){
	var isRepet=false;
	if(id==""){
		id=0;
	}
	 var formData=$('#form').serialize();
	 var  saveUrl="./caseHistory/tosave.spring?id="+id;
	 var caseList="./caseHistory/toList.spring";
	 var historyName=$("#historyName").val();
	 var secondaryPassword=$("#secondaryPassword").val();//二次访问密码
	 var birthday=$("#birthday").val();//生日
	 var profession=$("#profession").val();//职业
	 var sex=$("#sex").val();//性别
	 var maritalStatus=$("#maritalStatus").val();//婚姻
	 var phone=$("#phone").val();//联系方式
	 var allergicHistory=$("#allergicHistory").val();//过敏史
	 var previousHistory=$("#previousHistory").val();//既往史
	 var personalHistory=$("#personalHistory").val();//个人史
	 var familyHistory=$("#familyHistory").val();//家族史
	 var obstericalHistory=$("#obstericalHistory").val();//婚育史
	 var menstrualHistory=$("#menstrualHistory").val();//月经史
	 var presentIllness=$("#presentIllness").val();//   现病史
	 var physicalExamination=$("#physicalExamination").val();//体格检查结果
	 var accessoryExamination=$("#accessoryExamination").val();//辅助检结果
	 if(historyName==""){
		 alert("病历名称不能为空");
		 $("#historyName").focus();
		 return;
	 }else if(birthday==""){
		 alert("生日不能为空");
		 $("#birthday").focus();
		 return;
	 }else  if(sex==""){
		 alert("性别不能为空");
		 $("#sex").focus();
		 return;
	 }else if(maritalStatus==""){
		 alert("婚姻不能为空");
		 $("#maritalStatus").focus();
		 return;
	 }else if(phone==""){
		 alert("联系方式不能为空");
		 $("#phone").focus();
		 return;
	 }else  if(allergicHistory==""){
		 alert("过敏史不能为空");
		 $("#allergicHistory").focus();
		 return;
	 }else if(previousHistory==""){
		 alert("既往史不能为空");
		 $("#previousHistory").focus();
		 return;
	 }else if(personalHistory==""){
		 alert("个人史不能为空");
		 $("#personalHistory").focus();
		 return;
	 }else  if(familyHistory==""){
		 alert("家族史不能为空");
		 $("#familyHistory").focus();
		 return;
	 }else  if(obstericalHistory==""){
		 alert("婚育史不能为空");
		 $("#obstericalHistory").focus();
		 return;
	 }else  if(menstrualHistory==""){
		 if(sex==1){
			 alert("月经史不能为空");
			 $("#menstrualHistory").focus();
			 return;
		 }
		
	 }else  if(presentIllness==""){
		 alert("现病史不能为空");
		 $("#presentIllness").focus();
		 return;
	 }else if(secondaryPassword==""){
		 alert("访问密码不能为空");
		 $("#secondaryPassword").focus();
		 return;
	 }
	 isRepet=true;
	 var $loadingToast = $('#loadingToast');
		if ($loadingToast.css('display') != 'none') {
			return;
		}
		$loadingToast.show();
	 $.ajax({
		　　url : saveUrl,
		　　data : formData,
		　　type : "POST",
		　　success : function(data) {
		if(data[14]=="1"){
			setTimeout(function() {
				$loadingToast.hide();
				$("#toast").show();
				setTimeout(function() {
					$("#toast").hide();
					window.location.href=caseList;
				}, 1000);
			}, 1000);
			
		}else{
			alert("保存失败，请稍后保存");
		}
		　　},
		});
	
}
/**
 * 选择女时，出现月经史
 * @returns
 */
function selectMenstrual(){
	var sex=$("#sex").val();
	if(sex==1){//女
		$("#yuejing").show();
	}else{
		$("#yuejing").hide();
	}

}

/**
 * 新建病历
 * @returns
 */
function cteateCase(){
	var addurl="./caseHistory/addCase.spring";
	window.location.href=addurl;
}


function openimg(){
	if($("#openimg").hasClass("off")){
		$("#openimg").removeClass("off");
		$("#imghistory").hide();
	}else{
		$("#openimg").addClass("off");
		$("#imghistory").show();
	}
}

function openinquiry(){ 
	if($("#openinquiry").hasClass("off")){
		$("#openinquiry").removeClass("off");
		$("#inquiryhistory").hide();
	}else{
		$("#openinquiry").addClass("off");
		$("#inquiryhistory").show();
	}
}

function tableQueryParams(params) {
	var queryObj = {
		userCode : userCode
	};
	var newParams = $.extend(params,queryObj);
	return newParams;
}

function operFormatter(value, row) {
	var operTemp = $("#myCaseHistoryTemp").clone();
	var lis = operTemp.find("ul li");
	lis.eq(0).find("a").attr("href", "./jsp/caseHistory/medicalrecordDetail.jsp?id="+row.id);
	lis.eq(1).find("a").attr("onClick", "deleteMyCaseHistory(\""+row.id+"\")");	
	return operTemp.html();
}

function imgoperFormatter(value, row){
	var operTemp = $("#imghistoryTemp").clone();
	var lis = operTemp.find("ul li");
	lis.eq(0).find("a").attr("href", "./jsp/caseHistory/caseHistoryImgDetail.jsp?code="+row.code);
	lis.eq(1).find("a").attr("onClick", "deleteCaseHistoryImg(\""+row.id+"\")");	
	return operTemp.html();	
}

function deleteCaseHistoryImg(){
	$.ajax({
       	url: "./myCaseHistory/delCaseHistoryImg",
       	type: "POST",
       	data:{
			id :id       		
       	},
       	dataType: 'json',
       	cache: false,
       	success: function (ret) {
       	  	getMyCaseHistoryImg();
       	}
   });
}

function deleteMyCaseHistory(id){
	$.ajax({
       	url: "./medicalRecord/delById",
       	type: "POST",
       	data:{
			id :id       		
       	},
       	dataType: 'json',
       	cache: false,
       	success: function (ret) {
       	  	//getMyCaseHistoryImg();
			if(ret.resultCode==0){
				alert(ret.msg);
				window.location.reload();
			}else{
				alert(ret.msg);
			}

       	}
   });
	return;
}

</script>
<!-- <script type="text/javascript" src="js/caseHistory.js"></script> -->
<body ontouchstart>
<div class="container js_container">
</div>
<div class="page">
    <div class="bd">
        <div class="weui_grids">
       <div class="weui_cells_title" style="text-align: center;font-size: 18px;">病历列表
       <span id="userName" class="btn" onclick="changeRole();" style="vertical-align: initial !important;padding:1px !important;color: rgba(247, 47, 2, 0.5);width: 18%;"></span>
       </div>
		<%--<div class="weui_cells weui_cells_form">
            <div class="weui_cell weui_cell_switch">
                <div class="weui_cell_hd weui_cell_primary" style="font-weight: 600;">基础病历</div>
                <div class="weui_cell_ft">
                    <input class="weui_switch off" type="checkbox" id="openbase" onclick="openbase();">
                </div>
            </div>
        </div> --%>
      	<div class="weui_cells weui_cells_access"  id="basehistory" style="display:none;margin-top: -1px;position: relative;">
      		<table id="table" data-toolbar="#toolbar" data-toggle="table" data-row-style="rowStyle" data-classes="table  table-no-bordered"
		           data-minimum-count-columns="2"  data-cache="false" data-pagination="true"  data-striped="data-striped"
		           data-query-params="tableQueryParams"  style="word-break:break-all;"
		           data-side-pagination="server" data-page-size=20 data-url="./medicalRecord/getMedicalRecords">
		           <thead>
					<tr class="headTr">
						<th data-field="name" data-width="70%" ></th>
						<th data-field="operation" data-width ="30%" data-formatter="operFormatter"></th>
					</tr>
				</thead>
		    </table>

        </div>
		    <div id="myCaseHistoryTemp" style="display:none">
				<ul class="list-inline" style="margin:0px !important;float: right">
					<li role="presentation"><a role="button" class="btn btn-primary" style="padding : 5px !important;">详情</a></li>
					<li role="presentation"><a role="button" class="btn btn-danger" style="padding : 5px !important;">删除</a></li>
				</ul>
			</div>        
        
        <%--<div class="weui_cells weui_cells_form">
            <div class="weui_cell weui_cell_switch">
                <div class="weui_cell_hd weui_cell_primary" style="font-weight: 600;">图片病历</div>
                <div class="weui_cell_ft">
                    <input class="weui_switch off" type="checkbox" id="openimg" onclick="openimg();" >
                </div>
            </div>
        </div> --%>
      	<%--<div class="weui_cells weui_cells_access"  id="imghistory" style="display: none;margin-top: -1px">
      		  <table id="table" data-toolbar="#toolbar" data-toggle="table" data-row-style="rowStyle" data-classes="table  table-no-bordered"
		           data-minimum-count-columns="2"  data-cache="false" data-pagination="true"  data-striped="data-striped"
		           data-query-params="tableQueryParams" style="word-break:break-all;"
		           data-side-pagination="server" data-page-size=20 data-url="./myCaseHistory/getMyCaseHistoryImgs">
		           <thead>
					<tr class="headTr">
						<th data-field="name" data-width="60%" ></th>
						<th data-field="operation" data-width ="40%" data-formatter="imgoperFormatter"></th>
					</tr>
				</thead>
		    </table>
      		<a class="weui_cell" href="./jsp/caseHistory/uploadPic.jsp">
				<div class="weui_cell_bd weui_cell_primary" style="margin-left:48%;">
					<img src="./images/Add.png" alt="" style="width:25px;height:25px; margin-right:5px;display:block">
				</div>
			</a>
        </div>--%>
       	<%--<div id="imghistoryTemp" style="display:none">
			<ul class="list-inline" style="margin:0px !important;">
				<li role="presentation"><a role="button" class="btn btn-primary" style="padding : 1px !important;">详情</a></li>
				<li role="presentation"><a role="button" class="btn btn-danger" style="padding : 1px !important;">删除</a></li>
			</ul>
		</div>  --%>

       <%-- <div class="weui_cells weui_cells_form">
            <div class="weui_cell weui_cell_switch">
                <div class="weui_cell_hd weui_cell_primary" style="font-weight: 600;">简易病历</div>
                <div class="weui_cell_ft">
                    <input class="weui_switch off" type="checkbox" id="openinquiry" onclick="openinquiry();" >
                </div>
            </div>
        </div>--%>
        <div class="weui_cells weui_cells_access"  id="inquiryhistory" style="display: none;margin-top: -1px;">
        </div>
            </div>
            
            
            
        </div>
    </div>
      
</div>
	<section class="theleftmenu" style="height: 627px; display: none;">
		<span class="bg_mark" style="display: none;"></span>
		<div class="theleftmenu_con"  style="background-color: #fff;width: 90%;height:auto;margin-top: 30%;margin-left: 5%;text-align: center;">
			<p class="m_tit" style="font-size: 18px;padding-top: 5px;">请选择角色</p>
			<div class="weui_cells weui_cells_radio" id="role"></div> 
        	<a href="javascript:;" class="weui_btn weui_btn_plain_primary" style="margin: 3px;" onclick="commit();">确定</a>
		</div>
	</section>
	<div id="loadingToast" class="weui_loading_toast" style="display: none;">
				<div class="weui_mask_transparent"></div>
				<div class="weui_toast">
					<div class="weui_loading">
						<div class="weui_loading_leaf weui_loading_leaf_0"></div>
						<div class="weui_loading_leaf weui_loading_leaf_1"></div>
						<div class="weui_loading_leaf weui_loading_leaf_2"></div>
						<div class="weui_loading_leaf weui_loading_leaf_3"></div>
						<div class="weui_loading_leaf weui_loading_leaf_4"></div>
						<div class="weui_loading_leaf weui_loading_leaf_5"></div>
						<div class="weui_loading_leaf weui_loading_leaf_6"></div>
						<div class="weui_loading_leaf weui_loading_leaf_7"></div>
						<div class="weui_loading_leaf weui_loading_leaf_8"></div>
						<div class="weui_loading_leaf weui_loading_leaf_9"></div>
						<div class="weui_loading_leaf weui_loading_leaf_10"></div>
						<div class="weui_loading_leaf weui_loading_leaf_11"></div>
					</div>
					<p class="weui_toast_content">请稍候...</p>
				</div>
			</div>
</body>
</html>
